﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace PaypalConverterSite
{
    public partial class Register : System.Web.UI.Page
    {
        protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
        {
            // Determine the checkbox values.
            //CheckBox subscribeCheckBox =
            //  (CheckBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("SubscribeCheckBox");
            //CheckBox shareInfoCheckBox =
            //  (CheckBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ShareInfoCheckBox");
            TextBox userNameTextBox =
              (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName");

            //MembershipUser user = Membership.GetUser(userNameTextBox.Text);
            ////user.Comment = "Subscribe=" + subscribeCheckBox.Checked.ToString() + "&" +
            ////               "ShareInfo=" + shareInfoCheckBox.Checked.ToString();
            //Membership.UpdateUser(user);

            // Show or hide the labels based on the checkbox values.
            //Label subscribeLabel =
            //  (Label)CreateUserWizard1.CompleteStep.ContentTemplateContainer.FindControl("SubscribeLabel");
            //Label shareInfoLabel =
            //  (Label)CreateUserWizard1.CompleteStep.ContentTemplateContainer.FindControl("ShareInfoLabel");

            //subscribeLabel.Visible = subscribeCheckBox.Checked;
            //shareInfoLabel.Visible = shareInfoCheckBox.Checked;
            Roles.AddUserToRole(userNameTextBox.Text, "Subscriber");

                
        }

        private bool UserExists(string username)
        {
            if (Membership.GetUser(username) != null) { return true; }

            return false;
        }

        protected void CreateUserWizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)
        {
            if (e.CurrentStepIndex == 0)
            {
                if (SearchAccount.Text.Trim() == "" || UserExists(SearchAccount.Text))
                {
                    SearchAccountMessage.Text = "That account already exists. Please select an different account name.";
                    e.Cancel = true;
                }
                else
                {
                    TextBox userName =
                      (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName");
                    userName.Text = SearchAccount.Text;
                    SearchAccountMessage.Text = "";
                    e.Cancel = false;
                }
            }
        }

        //public void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
        //{

        //    // Create an empty Profile for the newly created user
        //    ProfileCommon p = (ProfileCommon)ProfileCommon.Create(CreateUserWizard1.UserName, true);

        //    // Populate some Profile properties off of the create user wizard
        //    p.Country = ((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Country")).SelectedValue;
        //    p.Gender = ((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Gender")).SelectedValue;
        //    p.Age = Int32.Parse(((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Age")).Text);

        //    // Save the profile - must be done since we explicitly created this profile instance
        //    p.Save();
        //}
        //public void AssignUserToRoles_Activate(object sender, EventArgs e)
        //{

        //    // Databind list of roles in the role manager system to a listbox in the wizard
        //    AvailableRoles.DataSource = Roles.GetAllRoles(); ;
        //    AvailableRoles.DataBind();
        //}

        //// Deactivate event fires when user hits "next" in the CreateUserWizard 
        //public void AssignUserToRoles_Deactivate(object sender, EventArgs e)
        //{

        //    // Add user to all selected roles from the roles listbox
        //    for (int i = 0; i < AvailableRoles.Items.Count; i++)
        //    {
        //        if (AvailableRoles.Items[i].Selected == true)
        //            Roles.AddUserToRole(CreateUserWizard1.UserName, AvailableRoles.Items[i].Value);
        //    }
        //}
    }
}
